package org.example.corpus.corpuscenter.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.corpus.model.Corpus;

import java.util.List;

@Mapper
public interface CorpusDao {

    List<Corpus> getCorpusList(int offset, int pageSize,String keyword);

    @Select("<script>" +
            "SELECT * FROM tb_corpus " +
            "WHERE user_id = #{userId} " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "AND name LIKE CONCAT('%', #{keyword}, '%') " +
            "</if>" +
            "LIMIT #{pageSize} OFFSET #{offset}" +
            "</script>")
    List<Corpus> getUserCorpusList(int offset, int pageSize, String keyword, int userId);

    Integer insertCorpus( Corpus corpus);

    List<Corpus> selectCorpus(String keyword);

    @Select("select * from tb_corpus where name = #{corpusName}")
    Corpus selectCorpusByName(String corpusName);

    @Select("select * from tb_corpus where id = #{corpusId}")
    Corpus selectCorpusById(int corpusId);
}
